<?
	include($_SERVER['DOCUMENT_ROOT'].'/admin/template.php');
	
	$restId = $_POST["rest_id"];
	$week = $_POST["week"];
	$link = getDbLink();
?>

<form method = "post" action = "/admin/menuplan/updateMenuPlan.php">
	<table>
		<?
			$daysOfWeek = array("Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag");
			
			for ($i = 1; $i < 6; ++$i)
			{
				$day = $daysOfWeek[$i-1];
				$timestamp = getDateforWeek($i, date("W"));
				$thisdate = date("Y-m-d", getDateforWeek($i, date("W")));
				$query = sprintf("select id, food_text from menu_food where restaurant_id = %d and menu_date = '%s'", $restId, $thisdate);
				$result = mysql_query($query, $link);
				$numberOfMenus = mysql_num_rows($result);
				
				// Print menu number
				//if ($i == 1)
				//{
				//	echo "<tr>";
				//	for ($menuNumber = 1; $menuNumber <= $numberOfMenus; ++$menuNumber)
				//	{
				//		echo "<td><h3>Menu $menuNumber</h3></td>";
				//	}
				//	echo "</tr>";
				//}
				
				// Print day
				echo "<tr>";
				for ($j = 0; $j < $numberOfMenus; ++$j)
				{
					echo "<td><b>$day:</b></td>";
				}
				//echo "</tr>";
				
				// Print text area
				//echo "<tr>";
				while ($rv = mysql_fetch_array($result))
				{
					echo "<td>";
					$id = $rv["id"];
					drawTextArea("$id", $rv["food_text"]);
					echo "</td>";
				}
				echo "</tr>";
			}
		?>
		<tr>
			<td>
				<center><input type = "submit" value = "Speichern"></center>
			</td>
		</tr>
	</table>
</form>
	
<?
	function getFoodForDate($restId, $week, $day)
	{
		$link = getDbLink();
		$thisdate = date("Y-m-d",getDateforWeek($day,date($week)));
		$query = sprintf("select food_text from menu_food where restaurant_id = %d and menu_date = '%s'", $restId, $thisdate);
		$rv = mysql_fetch_array(mysql_query($query,$link));
		return $rv["food_text"];
	}
?>